package com.hup.utils.swing.screenShot;

import com.hup.utils.commons.hardware.MouseUtil;
import com.hup.utils.swing.screenShot.ScreenShotUtil.ShotType;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 取色的鼠标功能,功能描述:{@link ScreenShotLabel}
 * @author hugan
 * @date 2020/5/10
 */
class ColorMouseGesture extends MouseAdapter {

    private final ScreenShotLabel label;

    public ColorMouseGesture(ScreenShotLabel label) {
        this.label = label;
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        mouseMoved(e);
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        label.curX = e.getX();
        label.curY = e.getY();
        label.magnifierWindow.updateLocation(label.curX, label.curY);
        label.repaint();
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        mouseMoved(e);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        ShotType shotType = label.callback.shotType();
        if (MouseUtil.isLeftButton(e) && e.getClickCount() >= shotType.applyClickCount) {
            label.applyResult();
        } else if (MouseUtil.isRightButton(e)) {
            label.callback.getFrame().dispose();
        }
    }

}
